import request from 'umi-request';
import type {
  Submission,
  ResultVOSubmission,
  ResultVOPageSubmission,
  ResultVOListSubmission
} from 'src/types/openapi';

export async function addSubmission(data: Submission) {
  return request<ResultVOSubmission>('/api/submissions', {
    method: 'POST',
    data,
  });
}

export async function runSampleTest(data: Submission) {
  return request<ResultVOListSubmission>('/api/submissions/sample-test', {
    method: 'POST',
    data,
  });
}


export async function getSubmissionById(submission_id: string) {
  return request<ResultVOSubmission>(`/api/submissions/${submission_id}`);
}

export async function getSubmissionByUserId(userId: string, page: string, size: string) {
  return request<ResultVOPageSubmission>(`/api/submissions/user/${userId}`, {
    params: { page, size },
  });
}

export async function getSubmissionByProblemId(problemId: string, page: string, size: string) {
  return request<ResultVOPageSubmission>(`/api/submissions/problem/${problemId}`, {
    params: { page, size },
  });
}

export async function getSubmissionByUserIdAndProblemId(
  userId: string,
  problemId: string,
  page: string,
  size: string,
) {
  return request<ResultVOPageSubmission>(
    `/api/submissions/user/${userId}/problem/${problemId}`,
    {
      params: { page, size },
    },
  );
}
